Telegram Group & Telegram Channel
134. Program to delete a node for a given element from linked list.

#include <stdio.h>
#include<stdlib.h>

typedef struct node {
int data;
struct node *next;
}Node;

int main(void)
{
Node*temp;
Node*start=NULL;
Node* p=NULL;

int n;
scanf("%d",&n);

while(n--)
{
temp=(Node *)malloc(sizeof(struct node));
scanf("%d",&temp->data);
temp->next=NULL;

if(start==NULL)
{
start=temp;
p=temp;
}
else
{
p->next=temp;
p=temp;
}
}

printf("Element to delete : ");
int ele; scanf("%d",&ele); printf("%d\n",ele);
Node*prev=start;
Node*cur=start;

while(cur!=NULL)
{
if(start->data==ele)
{
start=start->next;
}

if(cur->data==ele)
{
prev->next=cur->next;
free(cur);
break;
}
prev=cur;
cur=cur->next;

if(cur==NULL)
{
printf("Element doesn't exist!");
exit(0);
}
}

while(start!=NULL)
{
if(start->next!=NULL)
printf("%d->",start->data);
else
printf("%d",start->data);

start=start->next;
}

return 0;
}
#program_by : @freakyLuffy



tg-me.com/C_Codings/195
Create:
Last Update:

134. Program to delete a node for a given element from linked list.

#include <stdio.h>
#include<stdlib.h>

typedef struct node {
int data;
struct node *next;
}Node;

int main(void)
{
Node*temp;
Node*start=NULL;
Node* p=NULL;

int n;
scanf("%d",&n);

while(n--)
{
temp=(Node *)malloc(sizeof(struct node));
scanf("%d",&temp->data);
temp->next=NULL;

if(start==NULL)
{
start=temp;
p=temp;
}
else
{
p->next=temp;
p=temp;
}
}

printf("Element to delete : ");
int ele; scanf("%d",&ele); printf("%d\n",ele);
Node*prev=start;
Node*cur=start;

while(cur!=NULL)
{
if(start->data==ele)
{
start=start->next;
}

if(cur->data==ele)
{
prev->next=cur->next;
free(cur);
break;
}
prev=cur;
cur=cur->next;

if(cur==NULL)
{
printf("Element doesn't exist!");
exit(0);
}
}

while(start!=NULL)
{
if(start->next!=NULL)
printf("%d->",start->data);
else
printf("%d",start->data);

start=start->next;
}

return 0;
}
#program_by : @freakyLuffy

BY C Language πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/C_Codings/195

View MORE
Open in Telegram


C Language ‍ Telegram | DID YOU KNOW?

Date: |

That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.

NEWS: Telegram supports Facetime video calls NOW!

Secure video calling is in high demand. As an alternative to Zoom, many people are using end-to-end encrypted apps such as WhatsApp, FaceTime or Signal to speak to friends and family face-to-face since coronavirus lockdowns started to take place across the world. There’s another optionβ€”secure communications app Telegram just added video calling to its feature set, available on both iOS and Android. The new feature is also super secureβ€”like Signal and WhatsApp and unlike Zoom (yet), video calls will be end-to-end encrypted.

C Language ‍ from it


Telegram C Language πŸ‘¨β€πŸ’»
FROM USA